#pragma once

#include <string>
#include <vector>

#include "Device.h"
#include "Texture.h"
#include "Effect.h"
#include "Camera.h"

namespace Crows3D
{
   class TextRenderer
   {
   private:
      struct Vertex2DPositionTexture
      {
         D3DXVECTOR4 position; // x/y position
         D3DXVECTOR2 texture;  // Texture coordinate
      };

	   struct CharData
	   {
		   float left, right;
		   int size;
	   };

	   struct TextLine
	   {
		   ID3D11Buffer *vertexBuffer, *indexBuffer;
		   int numVerts, numIndices, length;
		   float red, green, blue;
	   };


      static const int MAX_CHARACTERS_PER_LINE = 100;


      // font texture and shader
      Texture* texture;
      EffectPosition2DTexture* effect;

      // font data
      CharData* charData;

      // Contains all the data to render a line of text
      std::vector<TextLine*> lines;

      int numLines;

   public:
      TextRenderer(void);
      ~TextRenderer(void);

      bool Initialize(Crows3D::Device *dev, std::string fontFile, Texture* fontTexture, EffectPosition2DTexture* fontEffect);

      int  CreateLine(Crows3D::Device *dev);

      bool DeleteLine(int index);

      bool UpdateLine(Crows3D::Device *dev, int index, std::string text, float x, float y, float screenWidth, float screenHeight);

      void RenderLines(Crows3D::Device *dev, Crows3D::Camera* cam);

   private:
      bool InitializeBuffers(Crows3D::Device *dev, int index);
   };
}